﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Xna.Framework;

namespace girapong
{
    public static class general
    {
        public static Boolean isInterval(double value, double a, double b)
        {
            double higher = doubleHigher(a, b);
            double minor;
            if (a == higher) minor = b;
            else minor = a;
            return (value >= minor) && (value <= higher);
        }
        public static double doubleHigher(double a, double b)
        {
            if (a >= b) return a;
            return b;
        }
        public static double doubleMinor(double a, double b)
        {
            if (a <= b) return a;
            return b;
        }
        public static Boolean intersection(Image i, System.Windows.Shapes.Rectangle rE)
        {
            Thickness m = i.Margin;
            return intersection(m.Left, m.Top, i.Width, i.Height, rE);
        }
        public static Boolean intersection(System.Windows.Shapes.Ellipse e, System.Windows.Shapes.Rectangle rE)
        {
            Thickness m = e.Margin;
            return intersection(m.Left, m.Top, e.Width, e.Height, rE);
        }
        public static Boolean intersection(System.Windows.Shapes.Rectangle r, System.Windows.Shapes.Rectangle rE)
        {
            Thickness m = r.Margin;
            return intersection(m.Left, m.Top, r.Width, r.Height, rE);
        }
        public static Boolean intersection(double x, double y, double w, double h, System.Windows.Shapes.Rectangle rE)
        {
            double bIzq = x;
            double b_rELeft = rE.Margin.Left;
            double bDcha = bIzq + w;
            double b_reRight = b_rELeft + rE.Width;

            double bTop = y;
            double b_rETop = rE.Margin.Top;

            double bBottom = bTop + h;
            double b_reBottom = b_rETop + rE.Height;

            return ((((bIzq >= b_rELeft) && (bIzq <= b_reRight)) || ((bDcha >= b_rELeft) && (bDcha <= b_reRight)))
                && (((bTop >= b_rETop) && (bTop <= b_reBottom)) || ((bBottom >= b_rETop) && (bBottom <= b_reBottom))));
        }
        public static Vector2 generateRandomVectorByModule(int module_)
        {
            Random n = new Random();
            int module;
            if (module_ == 0) module = 1;
            else module = module_;
            double average = module / solid.sqrt;
            average *= 2;
            int max = (int)average;
            float cX = (float)n.Next(1, max);
            float cY = (float)max - cX;
            max = n.Next(2);
            float dec = (float)(n.Next(1, 10) - 1) / 10;
            cX += dec;
            dec = (float)(n.Next(1, 10) - 1) / 10;
            cY += dec;
            if (max % 2 == 0) cX = -cX;
            max = n.Next(2);
            if (max % 2 == 0) cY = -cY;
            return new Vector2(cX, cY);
        }
        public static Vector2 generateRandomOnBottomArrowVectorByModule(int module_)
        {
            Random n = new Random();
            int module;
            if (module_ == 0) module = 1;
            else module = module_;
            double average = module / solid.sqrt;
            average *= 2;
            int max = (int)average;
            float cX = (float)n.Next(1, max);
            float cY = (float)max - cX;
            max = n.Next(2);
            float dec = (float)(n.Next(1, 10) - 1) / 10;
            cX += dec;
            dec = (float)(n.Next(1, 10) - 1) / 10;
            cY += dec;
            if (max % 2 == 0) cX = -cX;
            return new Vector2(cX, cY);
        }
    }
}
